#include <iostream>
#include <string.h>
using namespace std;

class Computer{
private:
    double _price;
    char *_brand;
    static Computer *_pInstance;


public:
    static Computer *getInstance(){
        if(_pInstance == nullptr){
            _pInstance = new Computer(0, "huawei");
        }
        return _pInstance;
    }

    void init(double price, const char *brand){
        if(_brand){
            delete [] _brand;
        }
        _brand = new char[strlen(brand) + 1]();
        strcpy(_brand, brand);

        _price = price;
    }

    void print() const{
        cout << "(" << this->_price
             << "," << this->_brand
             << ")" << endl;
    }
    // 没有this指针
    static void destroy(){
        if(_pInstance){
            delete _pInstance;
            _pInstance = nullptr;
        }
        cout << "delete" << endl;
    }


private:
    Computer(double price, const char *brand)
    : _price(price), _brand( new char[strlen(brand) + 1]()) {
        strcpy(_brand, brand);
        cout << "Constructor" << endl;
    }
    ~Computer(){
        cout << "~Computer" << endl;
    }
    /**
     * 删除拷贝构造，赋值运算符
     */
    Computer(Computer &rhs) = delete;
    Computer &operator=(const Computer& rhs) = delete;
};
Computer* Computer::_pInstance = nullptr;

void test0(){
    Computer::getInstance()->print();
    // cout << Point::getInstance() << endl;

    Computer::getInstance()->init(8888, "google");
    Computer::getInstance()->print();

    Computer::destroy();


}


int main(int argc, char *argv[]){
    test0();
    return 0;
}

